<template>
    <div>
        <el-table :data="list"  :show-header="false" @row-click="handleCheckRow">
            <el-table-column prop="noticeTitle" label="标题" show-overflow-tooltip=""></el-table-column>
            <el-table-column label="创建时间" width="150">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column width="80" label="读取状态">
                <el-button slot="header" type="text" size="mini">查看全部</el-button>
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.readStatus==1">已读</el-tag>
                    <el-tag v-else type="danger">未读</el-tag>
                </template>
            </el-table-column>
        </el-table>
        <el-card shadow="never" :style="{borderWidth: '0'}" :body-style="{padding:'10px'}">
            <el-button type="text" icon="el-icon-search" @click="handleCheckAll" size="mini">查看全部</el-button>
        </el-card>

        <el-dialog title="查看" :visible.sync="open" width="780px" append-to-body destroy-on-close>
            <el-form v-if="open" ref="form" :model="form"  label-width="80px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="通知标题" prop="noticeTitle">
                            <el-input v-model="form.noticeTitle" placeholder="请输入通知标题" :readonly="true" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="内容">
                            <EditorOld v-model="form.noticeContent" :min-height="192" :readOnly="true" :showToolbar="false" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import * as api from "@/api/system/notice"
import EditorOld from "@/components/Editor/indexOld.vue"
import {markRead} from "@/api/system/notice";

export default {
    name: 'MmvNotifyList',
    props: ['type'],
    components:{
      EditorOld
    },
    data() {
        return {
            list: [],
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                status: 0,
            },
            open: false,
            // 表单参数
            form: {},
        };
    },
    mounted() {
        this.getList();
    },
    methods: {
        getList() {
            const params = Object.assign({}, this.queryParams);
            if (this.type) {
                params.noticeType = this.type;
            }
            api.listNotice(params).then(response => {
                this.list = response.rows;
            })
        },
        handleCheckAll() {
            if (this.type == 1) {
                this.$router.push({ path: '/tenantCenter/car/message', });
            } else {
                this.$router.push({ path: '/tenantCenter/car/notice', });
            }
        },
        handleCheckRow(row) {
           this.form={};
           const noticeId = row.noticeId;
           api.getNotice(noticeId).then(response => {
               this.form = response.data;
               this.open = true;
                api.markRead(noticeId).then(res=>{
                  this.$IVue.$emit('getNotReadNotice')
                });
                this.getList();
           });

        },
    },
}
</script>
